/**
 * @file mvp_video.h
 * @author lky (linkunyu@macro-video.com)
 * @brief video API
 * @version 0.1
 * @date 2021-05-28
 * 
 * @copyright Copyright (c) 2021
 * 
 */
#ifndef __MVP_VIDEO_H__
#define __MVP_VIDEO_H__

#include "mvdef.h"
#include "time.h"

#if __cplusplus
extern "C" {
#endif

#ifndef MV_VIDEO_GROUP_NUM_MAX
#define MV_VIDEO_GROUP_NUM_MAX	2			/* 编译时根据方案进行配置镜头组上限 */
#endif
#define MV_IMG_OSD_STR_LEN		64

#pragma region [音视频媒体类ENUM]
/**
 * @brief Video Attributes : video channel
 */
typedef enum _video_channel {
    MV_VIDEO_MAIN_CHN = 0,
    MV_VIDEO_SUB_CHN,
    MV_VIDEO_MJPEG_CHN,
    MV_VIDEO_CHN_NUM_MAX
}MVP_VIDEO_CHN_E;

/**
 * @brief Video Attributes : Image attributes
 */
typedef enum _flip_mirror {
    MV_IMAGE_NORMAL  = 0x0,
    MV_IMAGE_H_FLIP  = 0x1,
    MV_IMAGE_V_FLIP  = 0x2,
    MV_IMAGE_VH_FLIP = MV_IMAGE_V_FLIP | MV_IMAGE_H_FLIP,
}MVP_VIDEO_FLIP_MIRROR_E;

/**
 * @brief Video Attributes : isp mode
 */
typedef enum _isp_env_mode {
    MV_ISP_ENV_DAY_MODE = 0,
    MV_ISP_ENV_NIGHT_MODE,
    MV_ISP_ENV_LIGHT_MODE,
    MV_ISP_ENV_STARLIGHT_MODE,
    MV_ISP_ENV_NUM_MODE
}MVP_ISP_MODE_E;

typedef enum _isp_hdr_mode {
    MV_ISP_HDR_NOT_SUPPORT = 0,
    MV_ISP_HDR_DISABLE     = 1,
    MV_ISP_HDR_ENABLE      = 2,
    MV_ISP_HDR_AUTO        = 3,
}MVP_ISP_HDR_MODE_E;

typedef enum _sensor_chn_e {
    MV_SENSOR_CHN_ID0 = 0,
    MV_SENSOR_CHN_ID1,

    MV_SENSOR_NUM1     = 1,
    MV_SENSOR_NUM2     ,
}MVP_SENSOR_CHN_E;

/**
 * @brief Video Attributes : frame type
 */
typedef enum _video_frame_type {
    MV_FRAME_TYPE_P,
    MV_FRAME_TYPE_I,
    MV_FRAME_TYPE_YUV
}MVP_VIDEO_FRAME_TYPE_E;

typedef struct _isp_attr
{
    mv_u16_t u16_isp_patch; ///< 细化差分序号
    mv_u16_t u16_isp_cust;  ///< 客制化分组, 0=默认
    mv_u8_t  u8_hdr_mode;   ///< [MVP_ISP_HDR_MODE_E]
    mv_u8_t  u8_isp_mode;   ///< [MVP_ISP_MODE_E]
}mvp_isp_attr_t;

/**
 * @brief Video Attributes : lens type
 */
typedef enum _video_les_type {
    MV_LENS_TYPE_NORMAL = 0,
    MV_LENS_TYPE_WALL_PANORAMIC,
    MV_LENS_TYPE_CEILLING_PANORAMIC
}MVP_VIDEO_LENS_TYPE_E;

/**
 * @brief Video Attributes : bitrate ctrl mode
 */
typedef enum _bitrate_ctrl_mode{
    MV_BR_MODE_CBR,
    MV_BR_MODE_VBR,
    MV_BR_MODE_CONST_QP,
    MV_BR_MODE_LOW_LATENCY,
    MV_BR_MODE_AVBR,
	MV_BR_MODE_TYPE_TOTAL
}MVP_VIDEO_BR_MODE_E;

/**
 * @brief Video Attributes : video encode frame type
 */
typedef enum _encode_type {
    MV_H264_ENC_TYPE = 1,
    MV_HEVC_ENC_TYPE,
    MV_MJPEG_ENC_TYPE,
}MVP_VIDEO_ENC_TYPE_E;

/**
 * @brief Video Attributes : video encode mode
 */
typedef enum _smart_mode {
    MV_SMART_MODE_DISABLE,
    MV_SMART_MODE_LTR,
    MV_SMART_MODE_S264
}MVP_VIDEO_SMART_MODE_E;

/**
 * @brief Video Attributes : jpeg encode mode
 */
typedef enum _jpeg_enc {
    MV_HARD_ENCODE,
    MV_SOFT_ENCODE
}MVP_MJPG_ENC_TYPE_E;

typedef enum _image_resolution_type_e
{
	MV_IMG_RES_TYPE_100W	= 0,
	MV_IMG_RES_TYPE_200W,
	MV_IMG_RES_TYPE_300W,
	MV_IMG_RES_TYPE_400W,
	MV_IMG_RES_TYPE_500W,
	MV_IMG_RES_TYPE_600W,
	MV_IMG_RES_TYPE_700W,
	MV_IMG_RES_TYPE_800W,
}mv_img_res_type_e;

#define MV_IMG_EDGE_H	0
#define MV_IMG_EDGE_V	1
#define MVDEV_MEDIA_RESOLUTION_BASE(H, V)	(mv_u32_t)(H*10000 + V)
#define MVDEV_MEDIA_WIDTH_VAL(type)			(mv_u16_t)(type/10000)		/* 获取 */
#define MVDEV_MEDIA_HEIGHT_VAL(type)		(mv_u16_t)(type%10000)
typedef enum _dev_video_resolution_base_value_e
{
	MV_IMG_TYPE_INVALID		= 0,
	/* 标准分辨率 */
	MV_IMG_TYPE_VGA_VAL		= MVDEV_MEDIA_RESOLUTION_BASE(640, 	360),		/* 16:9 */
	MV_IMG_TYPE_VGA_43_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(640, 	480),		/* 4:3 */
	MV_IMG_TYPE_D1_VAL		= MVDEV_MEDIA_RESOLUTION_BASE(720, 	576),		/*******/
	MV_IMG_TYPE_100W_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(1280, 720),		/* 16:9 */
	MV_IMG_TYPE_960P_43_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(1280, 960),		/* 4:3 130w */
	MV_IMG_TYPE_200W_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(1920, 1080),		/* 16:9 */
	MV_IMG_TYPE_200W_43_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(1600, 1200),		/* 4:3 */
	MV_IMG_TYPE_300W_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(2304, 1296),		/* 16:9 */
	MV_IMG_TYPE_300W_43_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(2048, 1536),		/* 4:3 */
	MV_IMG_TYPE_400W_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(2560, 1440),		/* 16:9 */
	MV_IMG_TYPE_400W_43_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(2304, 1728),		/* 4:3 */
	MV_IMG_TYPE_500W_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(2880, 1620),		/* 16:9 */
	MV_IMG_TYPE_500W_43_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(2560, 1920),		/* 4:3 */
	MV_IMG_TYPE_600W_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(3266, 1837),		/* 16:9 */
	MV_IMG_TYPE_600W_43_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(2863, 2147),		/* 4:3 */
	MV_IMG_TYPE_800W_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(3840, 2160),		/* 16:9 */
	MV_IMG_TYPE_800W_43_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(3264, 2448),		/* 4:3 */

	/* 新增分辨率 */

	/* 定制分辨率(非标准分辨率) */
	MV_IMG_TYPE_CUST_VAL	= MVDEV_MEDIA_RESOLUTION_BASE(9999, 9999),
}mv_img_res_base_val_e;

typedef enum _dev_video_resolution_level_e
{
	MV_IMG_LV_INVALID = 0,
	/* 标准分辨率 */
	MV_IMG_LV_VGA,
	MV_IMG_LV_VGA_43,
	MV_IMG_LV_D1,
	MV_IMG_LV_100W,
	MV_IMG_LV_960P_43,
	MV_IMG_LV_200W,
	MV_IMG_LV_200W_43,
	MV_IMG_LV_300W,
	MV_IMG_LV_300W_43,
	MV_IMG_LV_400W,
	MV_IMG_LV_400W_43,
	MV_IMG_LV_500W,
	MV_IMG_LV_500W_43,
	MV_IMG_LV_600W,
	MV_IMG_LV_600W_43,
	MV_IMG_LV_800W,
	MV_IMG_LV_800W_43,
	/* 新增分辨率 */
	
	MV_IMG_LV_MAX,
	/* 自定义分辨率 */
	MV_IMG_LV_CUST	 = 255,
}mv_img_res_base_lv_e;

typedef enum _dev_lens_type_e
{
	MVDEV_LENS_TYPE_NORMAL 			= 0,		/* 普通镜头 */
	MVDEV_LENS_TYPE_WALL_PANORAMIC,				/* 180度全景镜头 */
	MVDEV_LENS_TYPE_CEILLING_PANORAMIC,			/* 360度全景镜头(鱼眼) */
}mvdev_lens_type_e;

typedef enum _image_nightvision_mode_e
{
    MV_IMG_NIGHTVISION_AUTO_MODE = 0,			/* 自动切换模式 */
    MV_IMG_NIGHTVISION_MONO_MODE,				/* 夜视模式 */
    MV_IMG_NIGHTVISION_FULL_MODE,				/* 全彩模式 */
}mv_img_nightvision_mode_e;

typedef enum _talk_mode_e
{
    MV_TALK_INVALID_MODE = 0,					/* 无效值 */
    MV_TALK_HALF_MODE,							/* 半双工对讲 */
    MV_TALK_FULL_MODE,							/* 全双工对讲 */
}mv_talk_mode_e;

/**
 * @brief Sensor support list
 * @note All sensor
 */
typedef enum _SUPPORT_SENSOR_LIST_E {
    /* unknow sensor ID */
    SENSOR_ID_UNKNOWN = 0,

    /* 思特威 */
    SENSOR_ID_SC1345  = 0x1345,
    SENSOR_ID_SC1346  = 0x1346,
    SENSOR_ID_SC2235  = 0x2235,
    SENSOR_ID_SC2232  = 0x2232,
    SENSOR_ID_SC2232H = 0xcb71,
    SENSOR_ID_SC2230  = 0x2230,
    SENSOR_ID_SC2311  = 0x2311,
    SENSOR_ID_SC4236  = 0x4236,
    SENSOR_ID_SC4210  = 0x4210,
    SENSOR_ID_SC2315E = 0x223820, //与2232h共用一个驱动和isp文件，驱动读出来的sensorID是2232h的
    SENSOR_ID_SC3335  = 0x3335,   //0xcc1a,
    SENSOR_ID_SC3336  = 0x3336,
	SENSOR_ID_SC3338  = 0x3338,
    SENSOR_ID_SC2335  = 0x2335,   //0xcb14,
    SENSOR_ID_SC2336  = 0x2336,
    SENSOR_ID_SC2336P = 0x9b3a,
    SENSOR_ID_SC2332  = 0x2332,   //0xcb17,
    SENSOR_ID_SC2331  = 0x2331,   //
    SENSOR_ID_SC5238  = 0x5235,
    SENSOR_ID_SC223A  = 0x223a,   //0xcb3e  

    /* 格科微 */
    SENSOR_ID_GC1054  = 0x1054,
    SENSOR_ID_GC2023  = 0x2023,
    SENSOR_ID_GC2033  = 0x2033,
    SENSOR_ID_GC2053  = 0x2053,
    SENSOR_ID_GC2063  = 0x2063,
    SENSOR_ID_GC2083  = 0x2083, 
    SENSOR_ID_GC3003  = 0x3003,
    SENSOR_ID_GC4653  = 0x4653,

    /* unknown！！！ */
    SENSOR_ID_PS5270  = 0x5270,

    /* 成都微光 */
    SENSOR_ID_MIS2006 = 0x2006,
    SENSOR_ID_MIS2008 = 0x2008,
    // SENSOR_ID_MIS4001 = 0x4001,
    SENSOR_ID_MIS5001 = 0x5001,

    SENSOR_ID_AR0230  = 0x230,

    /*...more sensors ~~*/
    SUPPORT_SENSOR_LIST_NUM = 31, /* support sensor total num, if add a new sensor, need to change */
}MVP_SENSOR_LIST_E;

typedef enum _MVP_QOS_GROUP_E
{
    MVP_QOS_GROUP_LAN = 0,
    MVP_QOS_GROUP_WAN,
    MVP_QOS_GROUP_WAN_4G,
    MVP_QOS_GROUP_NUM,
}MVP_QOS_GROUP_E;

#pragma endregion [音视频媒体类ENUM]

#pragma region [测光类ENUM]
typedef enum _ifrm_adj_lv
{
    IRFM_ADJ_LV1 = 0,
    IRFM_ADJ_LV2,
    IRFM_ADJ_NUM,
}MVP_IRFM_LV_E;
#pragma endregion [测光类ENUM]

#pragma region [音视频媒体类STRUCT]

/**
 * @brief vi crop info
 * @param left   : crop left
 * @param top    : crop top
 * @param width  : crop  width
 * @param height : crop height
 */
typedef struct _crop_info {
    mv_s32_t left;
    mv_s32_t top;
    mv_s32_t width;
    mv_s32_t height;
}MVP_CROP_INFO_T;

/**
 * @brief video resolution
 * @param width  : video width
 * @param height : video height
 * 
 */
typedef struct _video_info {
    mv_s32_t width;
    mv_s32_t height;
}MVP_VIDEO_INFO_T;

/**
 * @brief Sensor Attributes
 * @param sensor_type : < T_SUPPORT_SENSOR_LIST_E >
 * @param sensor_manufacturers : [sc gc mis]
 * @param sensor_width :  sensor max width
 * @param sensor_height : sensor max height
 */
typedef struct _sensor_info {
    mv_s32_t sensor_num;
    struct _sensor_chn{
        mv_s32_t sensor_type;
        mv_v8_t  sensor_manufacturers[8];
        mv_s32_t sensor_width;
        mv_s32_t sensor_height;
    }sensor_chn[MV_VIDEO_GROUP_NUM_MAX];
}MVP_SENSOR_INFO_T;

typedef struct _vi_splice_attr_t
{
    mv_bool_t   bl_splicing_mode_en;				/* 是否开启多镜头画面拼接模式 */
    mv_u8_t		u8_isp_splice_sort_flip;		    /* 镜头拼接排序翻转(拼接模式适用) */
    struct _splice_private_attr_t
    {
        /* 每个镜头单独配置的参数 */
        mv_u8_t   	u8_isp_flipNmirror_reversal;	/* 镜头画面翻转状态取反(0/1),(针对镜头方向倒装) */
    }st_splice_priv_attr[MV_VIDEO_GROUP_NUM_MAX];
}MVP_VI_SPLICE_ATTR_T;

/**
 * @brief vi init attributes
 * @param vi_info : video resolution
 * @param vi_crop_info : < struct mv_crop_info_p >
 * @param sensor_info : < MV_SENSOR_INFO >
 * @param lens_type :  les_type < enum mv_video_les_type_p >
 */
typedef struct _vi_attr {
    mv_s32_t                lens_type;
    MVP_VIDEO_INFO_T        vi_info[MV_VIDEO_CHN_NUM_MAX];
    MVP_CROP_INFO_T         vi_crop;
    MVP_SENSOR_INFO_T       sensor_info;
    mv_u16_t                isp_patch; ///< 细化差分序号
    mv_u16_t                isp_cust;  ///< 客制化分组, 0=默认
    MVP_VI_SPLICE_ATTR_T    st_vi_splice_attr;
}MVP_VI_ATTR_T;

/**
 * @brief venc encode attributes
 * @param fps : venc fps
 * @param goplen : venc gop
 * @param target_kbps : venc target kbps
 * @param max_kbps :  venc max kbps
 * @param minqp : venc min qp
 * @param maxqp : venc max qp
 * @param min_framesize : venc I frame min framesize
 * @param max_framesize : venc I frame max framesize
 */
typedef struct mv_venc_bit_rate_attr {
    mv_u16_t fps;
    mv_u16_t goplen;
    mv_u16_t target_kbps;
    mv_u16_t max_kbps;
    mv_u16_t minqp;
    mv_u16_t maxqp;
    mv_u16_t min_framesize;
    mv_u16_t max_framesize;
}MVP_BIT_RATE_ATTR_T;

/**
 * @brief venc init attributes
 * @param venc_res : < MV_VIDEO_INFO_S >
 * @param bit_rate_attr : < MV_BIT_RATE_ATTR >
 * @param br_mode : < enum mv_bitrate_ctrl_mode_p >
 * @param encode_type : < enum mv_encode_type_p >
 * @param smat_mode : < enum mv_smart_mode >
 */
typedef struct mv_venc_attr_p {
    mv_u8_t  br_mode;
    mv_s32_t encode_type;
    mv_s32_t smart_mode;
    mv_s32_t jpeg_enc_type;
    MVP_VIDEO_INFO_T    venc_res;
    MVP_BIT_RATE_ATTR_T bit_rate_attr;
}MVP_VENC_ATTR_T;

#pragma endregion [音视频媒体类STRUCT]

#pragma region [测光类STRUCT]

typedef struct _irfm_phase_p
{
    mv_u8_t  u8_valid;
    struct _adjust_level{
        mv_u8_t  u8_valid;     /* phase switch: 0=invalid(bypass), else=valid; P.S: START&END must valid */
        mv_s32_t s32_upthr;    /* phase up   threshold */
        mv_s32_t s32_downthr;  /* phase down threshold */
    }table[IRFM_ADJ_NUM];
}mvp_irfm_phase_t;
#pragma endregion [测光类STRUCT]

#pragma region [屏显类STRUCT]
typedef struct _vo_info_t
{
    mv_s32_t s32_width;
    mv_s32_t s32_height;
    mv_s32_t s32_x;
    mv_s32_t s32_y;
}MVP_VO_INFO_T;

typedef struct _vo_attr {
    mv_u32_t              vo_framerate;    // 视频播放的帧率
    mv_u8_t               u8_video_pxlfmt; // 视频层像素格式
    mv_u8_t               u8_image_pxlfmt; // 图像层像素格式
    MVP_VO_INFO_T         vo_info;         // 图像分辨率,显示坐标
}MVP_VO_ATTR_T;

typedef struct _vdec_attr {
    mv_u8_t              u8_video_pxlfmt;       // 视频层像素格式
    MVP_VO_INFO_T        vdec_info;             // 图像分辨率，显示的坐标
}MVP_VDEC_ATTR_T;

typedef struct _screen_time_info{
    mv_u8_t      u8_language;        // 字体语言
    mv_s32_t     s32_color;          // 字体颜色
    mv_cv8ptr_t  cpv8_filename;      // 背景图文件
}MVP_SCREEN_TIME_INFO_T;
#pragma endregion [屏显类STRUCT]

#pragma region [码流控制STRUCT]
typedef struct _qos_attr_t{
    mv_u8_t     u8_fps;               // 视频帧率
    mv_s32_t    s32_kbps;             // 视频码率
    mv_u8_t     u8_min_QP;            // 最小QP
    mv_u8_t     u8_max_QP;            // 最大QP
    mv_u8_t     u8_min_frameSize;     // 最小帧大小
    mv_u8_t     u8_max_frameSize;     // 最大帧大小
}MVP_QOS_ATTR_T;
#pragma endregion [码流控制STRUCT]
// mv_s32_t mvp_qos_attr_get(mv_void_tv);

/**
 * @brief MV_VIDEO_GET_VENC_DATA : Callback Fun 
 * @param channel : < enum mv_vi_channel_p >
 * @param type    : < enum mv_video_frame_type_p >
 * @param frame_data : frame data
 * @param frame_len  : frame len
 */
typedef mv_s32_t (*MV_VIDEO_GET_VENC_DATA)(mv_s32_t channel, mv_s32_t type, mv_u8ptr_t frame_data, mv_s32_t frame_len, mv_s32_t flag);

/**
 * @brief MV_VIDEO_GET_RAW_DATA : Callback Fun 
 * @param channel : < enum mv_vi_channel_p >
 * @param type    : < enum mv_video_frame_type_p >
 * @param frame_data : frame data
 * @param frame_len  : frame len
 */
typedef mv_s32_t (*MV_VIDEO_GET_RAW_DATA)(mv_s32_t channel, mv_s32_t type, mv_u8ptr_t frame_data, mv_s32_t frame_len);

/**
 * @brief sensor 信息获取
 * @param sensor_info [out] < MVP_SENSOR_INFO_T * >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_isp_sensor_info_get(MVP_SENSOR_INFO_T *sensor_info);

/**
 * @brief sensor 数量同步，从配置文件读取再同步到mvp
 * 
 * @return  
 */
mv_s32_t mvp_isp_sensor_num_update(mv_s32_t s32_sensor_num);

/**
 * @brief sensor 类型获取
 * 
 * @return MVP_SENSOR_LIST_E 
 */
MVP_SENSOR_LIST_E mvp_isp_sensor_type_get();

/*********************************************
*           mvp vi 
**********************************************/

/**
 * @brief MV_VIDEO_GET_RAW_DATA : Callback Fun 
 * @param s32_led_status        : < 控制红外灯 >
 * @param s32_light_status      : < 控制白光灯 >
 */
typedef mv_s32_t (*MV_VIDEO_LED_CTRL_CB)(mv_s32_t s32_led_status, mv_s32_t s32_light_status);
/**
 * @brief 视频采集初始化
 * @param attr [in] < MVP_VI_ATTR_T * >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_video_vi_init(MVP_VI_ATTR_T *attr);

/**
 * @brief 视频采集反初始化
 * @param attr [in] < MVP_VI_ATTR_T * >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_video_vi_uninit(mv_void_t);

/**
 * @brief mvp_video_set_vi_crop : vi save crop param
 * @param[in] crop_X : crop offset for horizontal
 * @return
 *      success : dma memory blk pointer
 *      Othre : NULL 
 */
mv_s32_t mvp_video_set_vi_crop(mv_s32_t crop_X);

MVP_QOS_ATTR_T* mvp_video_qos_param_get(mv_s32_t s32_chn, mv_s32ptr_t table_len);

/**
 * @brief 获取最大单帧size，需要在vi_init 后调用
 * @param[in] ps32_kByte : The maximum frame unit is Kbyte
 * @param[in] ps32_Byte  : The maximum frame unit is Byte
 * @param[in] u8_chn     : 主/子码流
 * @return
 *      success : dma memory blk pointer
 *      Othre : NULL 
 */
mv_s32_t mvp_video_max_frame_size_get(mv_u8_t u8_chn, mv_s32ptr_t ps32_kByte, mv_s32ptr_t ps32_Byte);

mv_s32_t mvp_video_led_cb_set(MV_VIDEO_LED_CTRL_CB led_ctrl_cb);
mv_s32_t mvp_video_interval_enc_set(mv_s32_t s32_chn, mv_s32_t s32_enable, mv_s32_t s32_interval);
mv_s32_t mvp_video_interval_enc_get(mv_s32_t s32_chn, mv_u8ptr_t pu8_enable, mv_s32ptr_t ps32_interval);
/*********************************************
*           mvp venc 
**********************************************/

/**
 * @brief 编码通道初始化
 * @param chn  [in] < MVP_VIDEO_CHN_E >
 * @param attr [in] < MVP_VENC_ATTR_T * >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_video_venc_init(MVP_VIDEO_CHN_E chn, MVP_VENC_ATTR_T *attr);

/**
 * @brief 编码通道反初始化
 * @param chn [in] < MVP_VIDEO_CHN_E >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_video_venc_uninit(MVP_VIDEO_CHN_E chn);

/**
 * @brief 开启编码通道
 * @param chn [in] < MVP_VIDEO_CHN_E >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_video_venc_chn_enable(MVP_VIDEO_CHN_E chn);

/**
 * @brief 关闭编码通道
 * @param chn [in] < MVP_VIDEO_CHN_E >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_video_venc_chn_disable(MVP_VIDEO_CHN_E chn);

/**
 * @brief 开启视频编码功能
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_video_venc_start(MV_VIDEO_GET_RAW_DATA get_raw_data_cb, MV_VIDEO_GET_VENC_DATA get_venc_data_cb);

/**
 * @brief 停止视频编码功能
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_void_t mvp_video_venc_stop();

/**
 * @brief 修改编码属性
 * @param chn  [in] < MVP_VIDEO_CHN_E >
 * @param attr [in] < MVP_BIT_RATE_ATTR_T * >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_video_venc_attr_change(MVP_VIDEO_CHN_E chn, MVP_BIT_RATE_ATTR_T *attr);

/**
 * @brief 强制I帧
 * @param chn  [in] < MVP_VIDEO_CHN_E >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_video_request_idr_frame(MVP_VIDEO_CHN_E chn);

/**
 * @brief 生成JPG图片
 * @param pv8_jpeg_path  [in] 生成图片路径
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_video_mjpg_save_file(mv_v8ptr_t pv8_jpeg_path);

/**
 * @brief 生成JPG图片,并保存到buffer中
 * @param pv8_buffer        [in] buffer地址
 * @param s32_buffer_len    [in] buffer长度
 * @return mv_s32_t 
 * - success : date_len 成功返回jpeg长度
 * -  failed : < 0
 */
mv_s32_t mvp_video_mjpg_save_buffer(mv_v8ptr_t pv8_buffer, mv_s32_t s32_buffer_len);

/**
 * @brief 获取设备正在使用的isp文件名（全路径）
 * 
 * @return 路径字符串缓存地址
 */
mv_cv8ptr_t mvp_video_using_isp();

/**
 * @brief 获取设备使用的拼接isp文件名
 * @param isp_filename  [out] 文件名
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_video_ispfilename_get(mv_v8ptr_t isp_filename);

/**
 * @brief isp 文件备份
 * @param 
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS    成功说明mtd下面没有备份isp文件，备份成功
 * -  failed : < 0
 */
mv_s32_t mvp_video_ispfile_backup();

/**
 * @brief 获取视频编码分辨率
 * @param width         [out] 视频宽度
 * @param height        [out] 视频高度
 * @param interpolation [in] 是否插值
 * @param lens_type     [in] 镜头类型
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_video_get_resolution(mv_s32ptr_t width, mv_s32ptr_t height, mv_s32_t interpolation,mv_s32_t lens_type);

/**
 * @brief 检查isp文件是否需要更新(目前仅 alios 低功耗使用)
 * @param pstru_sensor_info     [in] sensor 信息
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_video_check_isp_upgrade(MVP_SENSOR_INFO_T* pstru_sensor_info);

/**
 * @brief 视频输出初始化
 * @param attr [in] < MVP_VO_ATTR_T * >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_video_vo_init(MVP_VO_ATTR_T *attr);
/**
 * @brief 视频输出反初始化
 * @return
 * - success : MV_EC_SUCCESS
 * - failed : < 0
 */
mv_s32_t mvp_video_vo_uninit();
/**
 * @brief 显示图像到屏幕
 * @param cpv8_filename 文件路径
 * @return 
 * - success : 0
 * - failed : -1
 */
mv_s32_t mvp_video_show_imgfile(mv_cv8ptr_t cpv8_filename);
/**
 * @brief 显示图像并叠加文字到屏幕的中间，y坐标可调，x坐标不可调
 * @param cpv8_filename [in] 图片文件路径
 * @param pv8_str [in] 要叠加的字符串
 * @param s32_fontsize [in] 叠加文字的大小
 * @param s32_maxwidth [in] 要叠加的字符串的最大宽度，单位：像素
 * @param s32_y [in] 叠加到图片的y轴的坐标
 * @param s32_color [in] 字体颜色
 * @return 
 * - success : 0
 * - failed : errno
 * @attention
 * （注意：该选项限制了显示的字符串经过渲染以后的像素点宽度）
 *  例如，设置了s32_fontsize=20，s32_maxlen=120，
 * 如果字符串通过渲染以后的像素宽度超过120，则字符串显示不全，超过的部分用省略号".."代替
 */
mv_s32_t mvp_video_show_img_with_text(mv_cv8ptr_t cpv8_filename, mv_v8ptr_t pv8_str, mv_s32_t s32_fontsize, 
                                                        mv_s32_t s32_maxwidth, mv_s32_t s32_y, mv_s32_t s32_color);
/**
 * @brief 屏幕显示时间
 * @param _tt [in] : 时间结构体
 * @param screen_time_info [in] : 背景图
 * @return 
 * - success : 0
 * - failed : errno
 */
mv_s32_t mvp_video_show_time(struct tm tt, mv_cv8ptr_t cpv8_filename);
/**
 * @brief 清空屏幕
 * @return 
 * - success : 0 
 * - failed : errno
 */
mv_s32_t mvp_video_vo_clear();
/**
 * @brief 修改视频输出属性
 * @param attr [IN] < MVP_VO_ATTR_T * >
 * @return 
 * - success ： 0
 * - failed ： errno
 */
mv_s32_t mvp_video_vo_attr_change(MVP_VO_ATTR_T *attr);
/**
 * @brief 视频解码初始化
 * @param attr [in] < vdec attribute >
 * @return 
 * - success : 0
 * - failed : errno
 */
mv_s32_t mvp_video_vdec_init(MVP_VDEC_ATTR_T *attr);
/**
 * @brief 视频解码反初始化
 */
mv_s32_t mvp_video_vdec_uninit();
/**
 * @brief 开始接收视频流进行解码在屏幕显示
 * @return 
 * - success : 0
 * - failed : errno
 */
mv_s32_t mvp_video_vdec_start();
/**
 * @brief 停止接收视频流进行解码
 * @return 
 * - success : 0
 * - failed : errno
 */
mv_s32_t mvp_video_vdec_stop();
/**
 * @brief 视频流解码显示到屏幕，仅支持h264
 * @param pu8_data_vaddr [in] : h264视频流缓冲区
 * @param u64_ts [in] : 时间戳
 * @param u32_data_size [in] : 缓冲区大小
 * @return 
 * - success : 0
 * - failed : -1
 */
mv_s32_t mvp_video_vo_show_stream(mv_u8ptr_t pu8_data_vaddr, mv_u64_t u64_ts, mv_u32_t u32_data_size);

/*********************************************
*           mvp isp 
**********************************************/
typedef enum dev_standard_mode {
    /* 抗频闪 */
	DEV_STANDARD_DEFAULT = 0,
	DEV_STANDARD_CLOSE   = 1,
	DEV_STANDARD_PAL     = 10,      /* 国内默认PAL制式 */
	DEV_STANDARD_NTSC    = 11,
}MVP_STANDARD_MODE_E;

typedef enum soft_irfeed_version
{
    SOFT_IRFEED_V1,
    SOFT_IRFEED_V2,
}MVP_SOFTIR_VERSION_E;

mv_s32_t  mvp_isp_mode_get();
mv_s32_t  mvp_isp_init(MVP_VI_ATTR_T *attr);
mv_s32_t  mvp_isp_uninit(mv_void_t);
mv_void_t mvp_isptool_start(mv_void_t);
mv_void_t mvp_isptool_stop(mv_void_t);
mv_s32_t  mvp_isp_get_irfm_phase(mvp_irfm_phase_t *pstru_phase_tb);

/**
 * @brief  获取软光敏测光方式版本
 * @return < MVP_SOFTIR_VERSION_E > 默认 SOFT_IRFEED_V1
 */
mv_s32_t  mvp_isp_softir_version_get();
mv_s32_t  mvp_isp_softir_level_get(mv_s32_t s32_curr_level);

mv_s32_t mvp_isp_exp_gain_get(mv_void_t);
mv_s32_t mvp_isp_exp_get(mv_void_t);
mv_s32_t mvp_isp_awb_get(mv_s32_t s32_gain);
mv_s32_t mvp_isp_qr_mode_set(mv_bool_t enable);

/**
 * @brief isp 模式设置
 * @param mode  [in] < MVP_ISP_MODE_E >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_isp_mode_set(MVP_ISP_MODE_E mode);

/**
 * @brief 频闪设置
 * @param mode  [in] < MVP_STANDARD_MODE_E >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_isp_standard_set(MVP_STANDARD_MODE_E mode);

/**
 * @brief 图像翻转设置
 * @param mode  [in] < MVP_VIDEO_FLIP_MIRROR_E >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_isp_flip_and_mirror(MVP_VIDEO_FLIP_MIRROR_E flip_mirror);

/*********************************************
*           mvp osd 
**********************************************/
#define CUSTOM_OSD_MAX_LEN 64
/**
 * @brief osd info
 * @param position : osd position < enum mv_osd_position_p >
 * @param osd_string: osd string, max len:128
 */
typedef struct _osd_info {
	mv_s16_t s16_x;
    mv_s16_t s16_y;
	mv_v8_t  av8_osd_str[CUSTOM_OSD_MAX_LEN];
}MVP_CUSTOM_OSD_INFO_T;
/**
 * @brief draw box color info
 * @param color : white green red
 * @param osd_string: 
 */
typedef enum _box_color
{
    OSD_BOX_WHITE,
    OSD_BOX_GREEN,
    OSD_BOX_RED,
    OSD_BOX_BLUE,
    OSD_BOX_YELLOW,
    OSD_FONT_WHITE  = OSD_BOX_WHITE,
    OSD_FONT_GREEN  = OSD_BOX_GREEN,
    OSD_FONT_RED    = OSD_BOX_RED,
    OSD_FONT_BLUE   = OSD_BOX_BLUE,
    OSD_FONT_YELLOW = OSD_BOX_YELLOW,
}MVP_BOX_COLOR_E;

/**
 * @brief time info, calibration osd time 
 * @param timezone : Time zone [-12 ~ 12]
 * @param time_zone_offset :  time zone offset [0 ~ 60]
 */
typedef struct _timezone_info_p {
    mv_s16_t s16_time_zone;
    mv_s16_t s16_time_zone_offset;
    mv_s8_t  s8_dst;
}MVP_TIMEZONE_INFO_T;

/**
 * @brief  OSD相关资源初始化
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_osd_init(mv_void_t);

/**
 * @brief OSD相关资源反初始化
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_osd_uninit(mv_void_t);

/**
 * @brief 开启OSD显示功能
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_osd_show_start(MVP_TIMEZONE_INFO_T *info);

/**
 * @brief 停止OSD显示功能
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_osd_show_stop(mv_void_t);

/**
 * @brief 同步时区信息
 * @param info 
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_osd_timezone_update(MVP_TIMEZONE_INFO_T *info);

typedef enum _osd_date_style {
	MVP_OSD_DATES_YMDHMS  = 0,
	MVP_OSD_DATES_12S     = 1,
	MVP_OSD_DATES_WDAY    = 2,
	MVP_OSD_DATES_DST     = 4,
	MVP_OSD_DATES_FOREIGN = 8, ///< 外国模板
}mvp_osd_date_style_e;

typedef enum _osd_style_ctrl {
    MVP_OSD_STYLE_CTRL_OVERWRITE = 0,
    MVP_OSD_STYLE_CTRL_BITSET    = 1,
    MVP_OSD_STYLE_CTRL_BITCLEAR  = 2,
}mvp_osd_style_ctrl_e;

/**
 * @brief 开/关时间戳显示
 * @param chn [in] < MVP_VIDEO_CHN_E >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_osd_time_enable(MVP_VIDEO_CHN_E chn);
mv_s32_t mvp_osd_time_disable(MVP_VIDEO_CHN_E chn);

/**
 * @brief 开/关自定义OSD显示
 * @param chn [in] < MVP_VIDEO_CHN_E >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_osd_custom_str_enable(MVP_VIDEO_CHN_E chn);
mv_s32_t mvp_osd_custom_str_disable(MVP_VIDEO_CHN_E chn);

/**
 * @brief 自定义OSD数据更新
 * @param chn  [in] < MVP_VIDEO_CHN_E >
 * @param info [in] < MVP_CUSTOM_OSD_INFO_T >
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_osd_custom_str_update(MVP_VIDEO_CHN_E chn, MVP_CUSTOM_OSD_INFO_T *info);

/**
 * @brief  开/关录像标志显示
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_osd_rec_enable(MVP_VIDEO_CHN_E chn);
mv_s32_t mvp_osd_rec_disable(MVP_VIDEO_CHN_E chn);

/**
 * @brief  低功耗受限模式下电池低电量图标显示
 * @return mv_s32_t 
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_osd_battery_enable(MVP_VIDEO_CHN_E chn);
mv_s32_t mvp_osd_battery_disable(MVP_VIDEO_CHN_E chn);

typedef enum _logo_chn
{
    LOGO_CHN_PRIVACY,
    LOGO_CHN_CUSTOM_PIC,
}MVP_LOGO_CHN_E;

typedef struct _custom_logo_attr
{
    mv_cv8ptr_t logo_filename;
    mv_s16_t    s16_x;
    mv_s16_t    s16_y;
    mv_s32_t    s32_align_center;
}MVP_CUSTOM_LOGO_T;

/**
 * @brief  LOGO显示开关
 * @return mv_s32_t
 * - success : MV_EC_SUCCESS
 * -  failed : < 0
 */
mv_s32_t mvp_osd_custom_logo_show(MVP_VIDEO_CHN_E chn, MVP_LOGO_CHN_E logo_chn, MVP_CUSTOM_LOGO_T *attr);
mv_s32_t mvp_osd_custom_logo_hide(MVP_VIDEO_CHN_E chn, MVP_LOGO_CHN_E logo_chn);

/**
 * @brief 设置主通道隐私遮挡
 * 
 * @param status 1：使能 0：不使能
 * @return mv_s32_t 
 * @retval MV_EC_SUCCESS 设置遮挡失败
 * @retval MV_EC_FAILED 
 */
mv_s32_t mvp_set_vpss_mask(mv_s32_t status);

#if __cplusplus
}
#endif

#endif